import Vue from 'vue'
import Router from 'vue-router'
import tabBar from '@/layout/tabBar'
import login from '@/view/login'
import index from '@/view/index'
import task from '@/view/task'
// import recordTask from '@/view/recordTask'
import recordEarn from '@/view/recordEarn'
import detailTask from '@/view/detailTask'
import fillInfo from '@/view/fillInfo'
import feedback from '@/view/feedback'
Vue.use(Router)

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'tabBar',
      component: tabBar,
      redirect: '/index',
      children: [
        {
          path: '/index',
          name: 'index',
          component: index
        }, {
          path: '/task',
          name: 'task',
          component: task,
          meta: {
            title: '发现'
          }
        }
      ]
    },
    //  {
    //   path: '/recordTask',
    //   name: 'recordTask',
    //   component: recordTask,
    //   meta: {
    //     title: '任务状态'
    //   }
    // },
    {
      path: '/recordEarn',
      name: 'recordEarn',
      component: recordEarn,
      meta: {
        title: '收益记录'
      }
    }, {
      path: '/detailTask',
      name: 'detailTask',
      component: detailTask,
      meta: {
        title: '任务详情'
      }
    }, {
      path: '/fillInfo',
      name: 'fillInfo',
      component: fillInfo,
      meta: {
        title: '填写信息'
      }
    }, {
      path: '/feedback',
      name: 'feedback',
      component: feedback,
      meta: {
        title: ''
      }
    }, {
      path: '/login',
      name: 'login',
      component: login,
      meta: {
        title: '登录'
      }
    }

  ]
})

// // 路由拦截器
// router.beforeEach((to, from, next) => {
//   console.log('to', to)
//   console.log('from', from)
//   // 确保一定要调用 next()
//   const token = localStorage.getItem('TOKEN') || null
//   if (!token) {
//     // 缓存中没有token，去首页
//     next({
//       path: '/index'
//     })
//   } else {
//     next()
//   }
// })

export default router
